package com.example.rabbitmq.controller;

import com.example.rabbitmq.config.RabbitmqConfig;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.nio.charset.StandardCharsets;
import java.time.LocalDateTime;

/**
 * @Description :
 * @Author : Bruce Lee
 * @CreateTime : 2024/11/14
 */

@Slf4j
@Component
public class RabbitmqConsumer {
    @RabbitListener(queues = RabbitmqConfig.DEAD_QUEUE_D)
    public void receive(Message message) {
        log.info("当前时间：{},收到死信队列信息：{}", LocalDateTime.now(), new String(message.getBody(), StandardCharsets.UTF_8));
    }

    @RabbitListener(queues = RabbitmqConfig.QUEUE)
    public void receiveByDelay(Message message) {
        log.info("当前时间：{},收到延迟队列信息：{}", LocalDateTime.now(), new String(message.getBody(), StandardCharsets.UTF_8));
    }
}